You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(deparser): ORDER BY USING OPERATOR(...) and keep pg_catalog."char" - #412
ORDER BY x USING pg_catalog.< was emitted verbatim, which is a syntax error. SortBy.useOp now goes through the existing operator formatter: qualified → USING OPERATOR(pg_catalog.<), bare → USING <.
pg_catalog."char" lost its schema ('x'::char), so it reparsed as bpchar. Internal "char" is now quoted via QuoteUtils, keeps its schema when present (qualified casts use the existing CAST(... AS pg_catalog."char") form), and keeps array bounds.
Tests: kitchen-sink fixtures __fixtures__/kitchen-sink/misc/{operator-names,typecast}.sql with regenerated round-trip suites, plus an exact-output assertion in packages/deparser/__tests__/misc/pg-catalog.test.ts.
❌ AST_MISMATCH: misc/typecast-18.sql
❌ DEPARSED SQL: SELECT 'x'::char
❌ DEPARSED SQL: SELECT x FROM ( VALUES (1), (2) ) AS t(x) ORDER BY x USING pg_catalog.<
PARSE ERROR: syntax error at or near "pg_catalog"
Test Suites: 3 failed, 3 total
No actionable comments were generated in the recent review.
Walkthrough
The deparser now quotes char type names in additional contexts and uses deparseOperatorName for SORTBY_USING operators. New SQL fixtures and tests cover these formatting cases.
Changes: Type name formatting
Layer / File(s)
Summary
Format char type names packages/deparser/src/deparser.ts, __fixtures__/kitchen-sink/misc/typecast.sql, packages/deparser/__tests__/kitchen-sink/misc-typecast.test.ts, packages/deparser/__tests__/misc/pg-catalog.test.ts
TypeName quotes char in all contexts and quotes the type in two-part pg_catalog names. Fixtures and tests cover casts and column definitions using qualified and unqualified "char".
ORDER BY operator formatting
Layer / File(s)
Summary
Format ORDER BY operators packages/deparser/src/deparser.ts, __fixtures__/kitchen-sink/misc/operator-names.sql, packages/deparser/__tests__/kitchen-sink/misc-operator-names.test.ts
SortBy uses deparseOperatorName for SORTBY_USING. Fixtures cover qualified and unqualified operators, including NULLS FIRST and NULLS LAST.
constructive-io/pgsql-parser#404: Both changes format qualified operator names in the deparser and update the operator-name fixture.
constructive-io/pgsql-parser#401: This PR introduces the typecast fixture and test structure updated to cover the pg_catalog."char" formatting.
Suggested reviewers:luxor-code-review
Merge Risk: Minimal · up to 1825d · assessed changes only
Path filters excluded changed files. This rating applies only to the assessed changes.
Security architecture risk: Minimal · up to 1825d
The changes correct how SQL is written without adding a way to execute it or changing who can access data. The reviewed change did not establish a new security risk.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
inferred — The directly affected surface is callers that consume SQL rendered from the affected AST forms. The reviewed change does not add an entrypoint or extend database privileges; downstream execution contexts were not established.
Trust Boundaries and Controls
observed — Operator formatting is not input validation. The base already emitted operator symbol text directly; the head still does so while adding identifier quoting for schema components of qualified names.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names two changes: ORDER BY USING OPERATOR(...) handling and keeping pg_catalog."char" in the deparser. The changeset matches both. The deparser.ts diff routes SortBy.useOp through deparseOp…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names two changes: ORDER BY USING OPERATOR(...) handling and keeping pg_catalog."char" in the deparser. The changeset matches both. The deparser.ts diff routes SortBy.useOp through deparseOperatorName and changes how TypeName quotes char and pg_catalog.char. The fixtures and tests cover the same two areas. The title is specific and describes the primary changes, though it lists two topics in one line.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two deparser bugs that broke round-trips:
ORDER BY x USING pg_catalog.<was emitted verbatim, which is a syntax error.SortBy.useOpnow goes through the existing operator formatter: qualified →USING OPERATOR(pg_catalog.<), bare →USING <.pg_catalog."char"lost its schema ('x'::char), so it reparsed asbpchar. Internal"char"is now quoted viaQuoteUtils, keeps its schema when present (qualified casts use the existingCAST(... AS pg_catalog."char")form), and keeps array bounds.Tests: kitchen-sink fixtures
__fixtures__/kitchen-sink/misc/{operator-names,typecast}.sqlwith regenerated round-trip suites, plus an exact-output assertion inpackages/deparser/__tests__/misc/pg-catalog.test.ts.Before the fix (commit 7d17c3f, tests only)
After (commit 1825d93)
Regress known-failures ratchets unchanged.
Implemented in session Fix deparser ORDER BY USING and "char" output
Review with Devin · Open in Devin Desktop
Summary by CodeRabbit
chartype casts and column definitions, preserving the correct quoting for qualified and unqualified type names.ORDER BYclauses that use operator-qualified ordering operators, including cases withNULLS FIRSTorNULLS LAST.